const express = require("express")
const articlerouter = express.Router()
const articleControl = require("../control/article")
const expressjoi = require("@escook/express-joi")
const { add_article_schema } = require("../scheam/article")

const multer = require("multer")
const path = require("path")
const storage = multer.diskStorage({
  destination: (req, file, callback) => {
    callback(null, path.join(__dirname, "../uploads"))
  },
  filename: (req, file, callback) => {
    callback(null, Date.now() + path.extname(file.originalname)) //得到文件的后缀名
  },
})
const upload = multer({
  storage,
})

articlerouter.post(
  "/add",
  upload.single("cover_img"),
  expressjoi(add_article_schema),
  articleControl.add
)

module.exports = articlerouter
